package com.situ.study.day10;

import org.junit.Test;

public class StringDemo {
    @Test
    public void test1() {
        String str1 = "abc";
        String str2 = new String("abc");
        String str3 = "abc";
        // ==比较的是变量指向的对象的地址值
        System.out.println(str1 == str2);//false
        System.out.println(str2 == str3);//false
        System.out.println(str1 == str3);//true

        // equals比较内容是不是相等
        System.out.println(str1.equals(str2));//true
        System.out.println(str2.equals(str3));//true
        System.out.println(str1.equals(str3));//true

        System.out.println(str1.length());//3
    }

    @Test
    public void test2() {
        String str = "Hello Java";
        System.out.println(str.length());
        System.out.println(str.charAt(1));//e
        System.out.println(str.indexOf('e'));//1

        char[] chars = str.toCharArray();
        // ['h','e','l']

        char[] array = {'j', 'a', 'v', 'a'};
        String str2 = new String(array);
        System.out.println(str2);// "java"
    }

    @Test
    public void test3() {
        String str = "  Java   ";
        System.out.println(str);
        System.out.println(str.trim());
    }
}
